package dome5;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 朵拉冒险
 * User: 王圆豪
 * Date: 2024-07-17
 * Time: 14:26
 */
public class Test {
    public static void move(int[] array, int i) {
        if (array[i] == i || array[i] == 0) {
            return;
        } else {
            array[0]++;
            int t = array[i];
            array[i] = 0;
            move(array, t);
        }
    }
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            array[i] = sc.nextInt();
        }
        int max = 1;
        array[0] = 0;
        for (int i = 1; i < n + 1; i++) {
            int[] a = array.clone();
            move(a, i);
            if (max < a[0]) {
                max = a[0];
            }
        }
        System.out.println(max);
    }
}
